"""
Simulated download firmware module with progress tracking
"""
import time

# 全局进度状态
_download_progress = 0

def download_firmware(device_id, firmware_version, progress_callback=None):
    """Simulate downloading firmware for a device with progress tracking."""
    global _download_progress
    
    print(f"Start downloading firmware - Device ID: {device_id}, Version: {firmware_version}")
    
    # 重置进度状态
    _download_progress = 0
    
    return {
        "status": "started",
        "message": f"Download started for firmware {firmware_version}",
        "device_id": device_id,
        "firmware_version": firmware_version
    }

def get_available_firmware():
    """Return a list of available firmware versions."""
    return [
        {"version": "v1.2.3", "size": "5MB", "description": "Latest stable version"},
        {"version": "v1.2.2", "size": "4MB", "description": "Previous version"},
        {"version": "v1.2.1", "size": "3MB", "description": "Older version"}
    ]

def check_download_progress():
    """Return current download progress and auto-increment."""
    global _download_progress
    
    # 如果进度小于100，自动增加进度
    if _download_progress < 100:
        # 每次增加4%，模拟4秒完成
        _download_progress = min(_download_progress + 4, 100)
    
    return _download_progress 